/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.ui.model;

import net.sourceforge.perforce.core.api.IPerforceServer;
import net.sourceforge.perforce.ui.IPerforceUIConstants;
import net.sourceforge.perforce.ui.PerforceUIPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
  * @version $Revision: 46 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class PerforceServerElement extends PerforceModelElement implements IWorkbenchAdapter
{
	// ---------------------------------------------------------- Public Methods (IWorkbenchAdapter)
	
	/** @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object) */
	public Object[] getChildren(Object o) 
	{
		if (!(o instanceof IPerforceServer))
		{
			return null;
		}

		IPerforceServer server = (IPerforceServer) o;
		return new Object[] 
		{
			new ProjectContainerElement(server), 
			new DepotContainerElement(server) 
		};		
	}

	/** @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(Object) */
	public ImageDescriptor getImageDescriptor(Object object) 
	{
		if (!(object instanceof IPerforceServer))
		{
			return null;
		}

		return PerforceUIPlugin.getPlugin().getImageDescriptor(
			IPerforceUIConstants.IMG_PERFORCE_SERVER);
	}

	/** @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(Object) */
	public String getLabel(Object o) 
	{
		if (!(o instanceof IPerforceServer))
		{
			return null;
		}
		
		IPerforceServer server = (IPerforceServer) o;
		return server.getPort() + ' ' + 
		       server.getClient() + ' ' + 
		       server.getUser();
	}

	/** @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object) */
	public Object getParent(Object o) 
	{
		return null;
	}
}
